﻿using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sustainalytics.Reporting.BusinessLogic
{
    public class ReportsDbContext
    {
        public const string ConnectionStringName = "WiredTiger";
        public const string DatabaseName = "Reports";

        private static readonly IMongoClient _client;
        private static readonly IMongoDatabase _database;

        static ReportsDbContext()
        {
            if (_database != null) return;

            var connectionString = ConfigurationManager.ConnectionStrings[ConnectionStringName].ConnectionString;

            //_client = new MongoClient(connectionString);
            _client = new MongoClient(new MongoClientSettings
            {
                MaxConnectionPoolSize = 1000,
                Server = new MongoServerAddress("localhost", 27017)
            });

            _database = _client.GetDatabase(DatabaseName);
        }

        public IMongoClient Client
        {
            get { return _client; }
        }

        public IMongoCollection<IndicatorsReportSection> IndicatorsReportSections
        {
            get { return _database.GetCollection<IndicatorsReportSection>(typeof(IndicatorsReportSection).Name); }
        }

        public IMongoCollection<ControversiesReportSection> ControversiesReportSections
        {
            get { return _database.GetCollection<ControversiesReportSection>(typeof(ControversiesReportSection).Name); }
        }

    }
}
